home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11366 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.3 KB

  1. Path: news.NetVision.net.il!news
  2. From: simchoni@netvision.net.il (Uri Simchoni)
  3. Newsgroups: comp.lang.c
  4. Subject: State machine design
  5. Date: 23 Mar 1996 10:09:25 GMT
  6. Organization: Simchoni Automation Systems Ltd
  7. Message-ID: <4j0ikl$9t5@news.NetVision.net.il>
  8. NNTP-Posting-Host: ts006p13.pop4a.netvision.net.il
  9. Mime-Version: 1.0
  10. X-Newsreader: WinVN 0.99.3
  11.  
  12. Hi,
  13.  
  14. I'm designing what I call a communication server. This a program which 
  15. receives messages from the network sends these messages to a device over 
  16. the serial port according to the device's proprietary protocol, and sends 
  17. the device's reply back over the network.
  18.  
  19. What I have in mind is to split the program into three basic modules. The 
  20. first one handles the RS232 communications, the second handles the 
  21. protocol logic and the third handles network traffic. Due to operating 
  22. system constraints (the OS is DOS and the computer the program runs on 
  23. should do other things), I can't use a model of "wait for a call from the 
  24. network, process that call and send your reply". I have to use some kind 
  25. of a state machine in the protocol logic module. The protocol logic 
  26. module will have functions that get called by the other modules whenever 
  27. an event occurs (clock tick, character arriving from the serial port, 
  28. request from the network, etc.)
  29.  
  30. After this LONG outline of the problem I get to my question. I'm 
  31. considering several designs for the state machine interface. One is to 
  32. have a distinct function for each type of event. The function decides 
  33. what to do according to module's internal data. Another is to have a 
  34. pointer to the function that handles all events for the current state. If 
  35. the state should change, the pointer is modified. Another design lays 
  36. somewhere in between - to have a sparate function for each type of event 
  37. and each state.
  38. Since my experience with such program is nearly zero, I cannot tell if 
  39. one design is preferable over the other (or if there's a better way of 
  40. doing these things). I'd appreciate anyone's input on the subject. I 
  41. think the primary issues that should be considered are ease of 
  42. implementation(handling reentrancy problems, etc), debugging, and 
  43. readability. Ease of making changes isn't a major issue since the serial 
  44. protocol is fixed and well established.
  45.  
  46. Thanks,
  47.  
  48. Uri Simchoni
  49. simchoni@netvision.net.il
  50.  
  51.